package br.com.emefs1.ftgourmet;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;

public class SplashScreen extends Activity {

	/**
	 * Splash screen timer
	 */
	private static int SPLASH_TIME_OUT = 3000;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);
		initAnimation();

		new Handler().postDelayed(new Runnable() {

			/*
			 * Showing splash screen with a timer. This will be useful when you
			 * want to show case your app logo / company
			 */

			@Override
			public void run() {
				// This method will be executed once the timer is over
				// Start your app main activity

				Intent i = new Intent(SplashScreen.this, MainActivity.class);
				startActivity(i);

				finish();
			}
		}, SPLASH_TIME_OUT);
	}

	private void initAnimation() {
		ImageView imageSplash = (ImageView) findViewById(R.id.imglogo);
		int width = imageSplash.getWidth();
		int height = imageSplash.getHeight();

		// Step1 : create the RotateAnimation object
		RotateAnimation anim = new RotateAnimation(180f, 360f, width / 2, 0.5f,
				height / 2, 0.5f);
		// Step 2: Set the Animation properties
		anim.setInterpolator(new LinearInterpolator());
		anim.setRepeatCount(0);
		anim.setDuration(SPLASH_TIME_OUT / 3);
		anim.setFillAfter(true);

		// Step 3: Start animating the image
		imageSplash.startAnimation(anim);
		// Later. if you want to stop the animation
		imageSplash.setAnimation(anim);
	}

}